package com.tepth.vehiclemaintenance.adapter;

import android.content.Context;
import android.support.graphics.drawable.VectorDrawableCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tepth.vehiclemaintenance.R;
import com.tepth.vehiclemaintenance.bean.VehicleMaintain;
import com.tepth.vehiclemaintenance.config.WorkStatusCode;

import java.util.List;

/**
 * Created by 张宇 on 2017/3/15.
 */

public class VehicleHistoryAdapter extends BaseQuickAdapter<VehicleMaintain, BaseViewHolder> {
    private Context mContext;
    private VectorDrawableCompat mDrawableCompatReady;
    private VectorDrawableCompat mDrawableCompatDoing;
    private VectorDrawableCompat mDrawableCompatComplete;

    public VehicleHistoryAdapter(Context context, int layoutResId, List<VehicleMaintain> data) {
        super(layoutResId, data);
        mContext = context;
        mDrawableCompatReady = VectorDrawableCompat.create(mContext.getResources(),
                R.drawable.vector_drawable_bus_on_hand, mContext.getTheme());
        mDrawableCompatDoing = VectorDrawableCompat.create(mContext.getResources(),
                R.drawable.vector_drawable_bus_maintenance, mContext.getTheme());
        mDrawableCompatComplete = VectorDrawableCompat.create(mContext.getResources(),
                R.drawable.vector_drawable_bus_complete, mContext.getTheme());
    }

    @Override
    protected void convert(BaseViewHolder helper, VehicleMaintain item) {
        helper.addOnClickListener(R.id.card_view);
        helper.setText(R.id.tv_maintain_time, "保养时间:" + item.getCompletedTime());
        helper.setText(R.id.tv_maintain_person, "竣检员:" + item.getCompletedPersonName());
        String code = item.getWorkStatusCode();
        helper.setVisible(R.id.layout_ready_work, false);
        switch (code) {
            case WorkStatusCode.READY_WORK:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatReady);
                helper.setImageDrawable(R.id.image_text, mContext.getResources()
                        .getDrawable(R.drawable.ready_text));
                helper.setVisible(R.id.layout_ready_work, true);
                break;
            case WorkStatusCode.UNDER_WORK:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatDoing);
                helper.setImageDrawable(R.id.image_text, mContext.getResources()
                        .getDrawable(R.drawable.doing_text));
                break;
            case WorkStatusCode.FINISH_WORK:
            case WorkStatusCode.COMPLETE_WORK:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatComplete);
                helper.setImageDrawable(R.id.image_text, mContext.getResources()
                        .getDrawable(R.drawable.done_text));
                break;
            default:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatReady);
                helper.setImageDrawable(R.id.image_text, mContext.getResources()
                        .getDrawable(R.drawable.ready_text));
                break;
        }
    }

}
